import { constantRoutes, asyncRoutes } from '@/router'
const state = {
  routes: []
}

const mutations = {
  setRoutes(state, data) {
    state.routes = [
      ...constantRoutes,
      ...data
    ]
  }
}

const actions = {
  filterRoutes(store, data) {
    // data可以通过路由守卫传递数据
    console.log('判断权限')
    // 获取权限列表
    console.log(data)
    // 获取所有路由
    console.log(asyncRoutes)
    const router = asyncRoutes.filter(router => data.includes(router.name))
    console.log(router)
    // console.log(constantRoutes)
    store.commit('setRoutes', router)
    return router
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
